<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //5! = 5*4*3*2*1
        //f(n)
        //f(1) = 1
        //f(2) = 2*f(1)
        //f(3) = 3*f(2)
        //n的阶乘 n!
        function fhelper(n, total) {
            if (n === 1) {
                return total;
            }
            return fhelper(n - 1, n * total);
        }

        function f(n) {
            return fhelper(n, 1);
        }

        console.log(f(5));
    </script>
</body>

</html>